package com.wpl.service.impl;

import com.wpl.bean.User;
import com.wpl.bean.UserExample;
import com.wpl.dao.UserMapper;
import com.wpl.service.ILoginService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 登录验证
 */
@Service
public class LoginServiceImpl implements ILoginService {

    @Resource
    private UserMapper userMapper;

    /**
     * 获取用户列表
     * @param username
     * @return
     */
    @Override
    public List<User> getUser(String username) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        return userMapper.selectByExample(userExample);
    }

    /**
     * 注销登录
     * @param user
     * @param username
     * @return
     */
    @Override
    public int loginout(User user,String username) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        return userMapper.updateByExampleSelective(user,userExample);
    }

    /**
     *
     * @param username
     * @return
     */
    @Override
    public int changeOnline(User user, String username) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        return userMapper.updateByExampleSelective(user,userExample);
    }


}
